﻿/// Login.aspx
/// This is supposed to be temporary until an actual login control is created.
/// Created by Dan Yatzeck on 11/5/2011

using System;
using Microsoft.Practices.ObjectBuilder;
using Common;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CSC440TeamOne.Shell.Views
{
	public partial class Login : Microsoft.Practices.CompositeWeb.Web.UI.Page, ILoginView
	{
		private LoginPresenter _presenter;
        private User currentUser;

		protected void Page_Load(object sender, EventArgs e)
		{
            if (Session["currentUser"] == null)
            {
                pnlLogin.Controls.Add(new LiteralControl("<a href='MyHealth/Registration.aspx'>Please register</a>"));
                return;
            }
            
            this.currentUser = Session["currentUser"] as User;

            pnlLogin.Controls.Add(new LiteralControl("Profile for " + this.currentUser.FirstName + " " + this.currentUser.LastName + "<br />"));
            pnlLogin.Controls.Add(new LiteralControl("<br />"));
            pnlLogin.Controls.Add(new LiteralControl("User registration confirmed: " + (this.currentUser.RegistrationConfirmed ? "Yes" : "No ... ") + "<br />"));
            pnlLogin.Controls.Add(new LiteralControl("Questionaire completed: " + (this.currentUser.QuestionaireCompleted ? "Yes" : "No ... ") + "<br />"));
            pnlLogin.Controls.Add(new LiteralControl("Questionaire pages completed: " + this.currentUser.QuestionaireLastPageCompleted.ToString() + "<br />"));
            pnlLogin.Controls.Add(new LiteralControl("<br />"));
            pnlLogin.Controls.Add(new LiteralControl("<a href='MyHealth/ConfirmRegistration.aspx'>Confirm Registration</a><br />"));
            pnlLogin.Controls.Add(new LiteralControl("<a href='MyHealth/HealthQuestionaire.aspx'>Continue Questionaire</a>"));
            

			if (!this.IsPostBack)
			{
				this._presenter.OnViewInitialized();
			}
			this._presenter.OnViewLoaded();
		}

		[CreateNew]
		public LoginPresenter Presenter
		{
			get
			{
				return this._presenter;
			}
			set
			{
				if(value == null)
					throw new ArgumentNullException("value");

				this._presenter = value;
				this._presenter.View = this;
			}
		}

		// TODO: Forward events to the presenter and show state to the user.
		// For examples of this, see the View-Presenter (with Application Controller) QuickStart:
		//	

	}
}

